<form id="form1" method="post">
<fieldset id="fd1" style="width:800px;">
	<legend><span>客服信息输入</span></legend>
	<div class="fieldset-body">
		<table class="form-table" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<td class="form-label" style="width:100px;">类型:</td>
				<td style="width:200px"><input name="types" id="types" class="mini-combobox" textField="name" valueField="id" value="1" data="JS.CONST[8]" allowInput="true" style="width:100%;"/></td>
			</tr>
		</table>
		<table class="form-table" id="tableone" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<td class="form-label" style="width:100px;">投诉机构:</td>
				<td style="width:200px"><input name="agency_id" id="agency_id" expandOnLoad="true" value="1" class="mini-treeselect" url="/common/agencyOne" multiSelect="false" textField="name" valueField="id" parentField="parent" checkRecursive="true" showFolderCheckBox="true" style="width:100%;"/></td>
				<td class="form-label customersh" style="width:100px;">顾客投诉人:</td>
				<td class="customersh" style="width:200px"><input name="customs_id1" id="customs_id1" class="mini-buttonedit" onbuttonclick="onButtonEdit(this,'/common/customer')" style="width:100%;"/></td>
				<td style="width:150px">&nbsp;</td>
			</tr>
			<tr>
				<td >&nbsp;</td>
				<td colspan="4"><font color="red">*顾客投诉人没有选择时、其他投诉人为必须输入！</font></td>
			</tr>
			<tr>
				<td class="form-label">其他投诉人:</td>
				<td colspan="3"><input name="contact1" id="contact1" class="mini-textbox" emptyText="[顾客投诉人]没有选择时、此项为必须输入！" style="width:100%;"/></td>
				<td >&nbsp;</td>
			</tr>
			<tr>
				<td class="form-label">标题(必须):</td>
				<td colspan="3"><input name="title1" id="title1" class="mini-textbox" emptyText="请输入主题" style="width:100%;"/></td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td class="form-label">内容(必须):</td>
				<td colspan="3"><input name="content1" id="content1" class="mini-textarea" emptyText="请输入备注" style="width:100%;"/></td>
				<td><a class="mini-button" iconCls="icon-add" onclick="btnAdd()">增加</a></td>
			</tr>
		</table>
		<table class="form-table" id="tabletwo" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<td class="form-label" style="width:100px;">合作意向:</td>
				<td style="width:200px"><input id="customerFlg" class="mini-combobox" textField="name" valueField="id" value="1" data="[{id:1,name:'是客户'},{id:2,name:'非客户'}]" allowInput="true" style="width:50%;"/><input id="customerFlgo" class="mini-combobox" textField="name" valueField="id" data="[{id:1,name:'非潜在客户'},{id:2,name:'是潜在客户'}]" allowInput="true" style="width:50%;"/></td>
				<td class="form-label" style="width:100px;">顾客咨询人:</td>
				<td style="width:200px"><input name="customs_id2" id="customs_id2" class="mini-buttonedit" onbuttonclick="onButtonEdit(this,'/common/customer')" style="width:100%;"/></td>
				<td style="width:150px">&nbsp;</td>
			</tr>
			<tr class="latent cust">
				<td>&nbsp;</td>
				<td colspan="4"><font color="red">*默认密码为：888888</font></td>
			</tr>
			<tr class="latent cust">
				<td class="form-label">登录名(必须):</td>
				<td><input name="login" id="login" class="mini-textbox" emptyText="请输入登录名" style="width:100%;"/></td>
				<td class="form-label">名称(必须):</td>
				<td><input name="name" id="name" class="mini-textbox" emptyText="请输入名称" style="width:100%;"/></td>
				<td>&nbsp;</td>
			</tr>
			<tr class="latent">
				<td>&nbsp;</td>
				<td colspan="4"><font color="red">*手机、座机、邮箱、QQ必须输入其中一项。</font></td>
			</tr>
			<tr class="latent">
				<td class="form-label">手机:</td>
				<td><input name="mobile" id="mobile" class="mini-textbox" vtype="rangeChar:11" emptyText="请输入手机号" style="width:100%;"/></td>
				<td class="form-label">座机:</td>
				<td><input name="tel" id="tel" class="mini-textbox" emptyText="请输入座机号" style="width:100%;"/></td>
				<td>&nbsp;</td>
			</tr>
			<tr class="latent">
				<td class="form-label">邮箱:</td>
				<td><input name="email" id="email" class="mini-textbox" vtype="email" emptyText="请输入手机号" style="width:100%;"/></td>
				<td class="form-label">QQ:</td>
				<td><input name="qq" id="qq" class="mini-textbox" emptyText="请输入QQ" style="width:100%;"/></td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td class="form-label">内容(必须):</td>
				<td colspan="3"><input name="content2" id="content2" class="mini-textarea" emptyText="请输入咨询内容" style="width:100%;"/></td>
				<td><a class="mini-button" iconCls="icon-add" onclick="btnAdd()">增加</a></td>
			</tr>
		</table>
	</div>
</fieldset>
</form>
<div class="mini-toolbar" style="padding:0px;margin:3px 0px 0px 0px;border-bottom:0;">
	<table style="width:100%;">
		<tr>
			<td style="width:100%;">
				类型:&nbsp;&nbsp;<input id="types2" class="mini-combobox" textField="name" valueField="id" data="JS.CONST[8]" allowInput="true" style="width:150px;"/>
				状态:&nbsp;&nbsp;<input id="status2" class="mini-combobox" textField="name" valueField="name" data="[{name:'未处理'},{name:'处理中'},{name:'已处理'},{name:'已作废'}]" allowInput="true" style="width:150px;"/>  
				标题:&nbsp;&nbsp;<input id="title2" class="mini-textbox" emptyText="请输入标题" style="width:150px;" onenter="onKeyEnter"/>   
				<a class="mini-button" iconCls="icon-search" id="search">查询</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-search" onClick="CustomerInfo('customs_id')" plain="true">查看顾客详情</a>
			</td>
		</tr>
	</table>
</div>
<div id="grid1" class="mini-datagrid" frozenStartColumn="0" frozenEndColumn="4" style="width:100%;height:42%;" idField="id" allowResize="false" borderStyle="border-left:0;border-right:0;" url="/service/complsintsTwo" >
	<div property="columns">
		<div type="indexcolumn"></div>
		<div field="types" headerAlign="center" align="center" width="60">类型</div>
		<div field="status" headerAlign="center" align="center" width="60">状态</div>
		<div field="customer" width="80">客户</div>
		<div field="contact" width="100">联系方式</div>
		<div field="title" width="100">标题</div>
		<div field="content" width="300">内容</div>
		<div field="inputStaff" width="60">客服</div>
		<div header="相关责任" headerAlign="center">
			<div property="columns">
				<div field="agency" width="120">责任机构</div>
				<div field="blamename" width="150">责任人</div>
			</div>
		</div>
		<div header="信息处理" headerAlign="center">
			<div property="columns">
				<div field="pagency" width="120">处理机构</div>
				<div field="pstaff" width="80">处理人</div>
				<div field="process_result" width="300">处理结果</div>
				<div field="process_time" dateFormat="yyyy-MM-dd HH:mm:ss" width="120">处理时间</div>
			</div>
		</div>
		<div field="updated" headerAlign="center" align="center" dateFormat="yyyy-MM-dd" width="100">创建时间</div>
	</div>
</div>
<script type="text/javascript">
mini.parse();
$("#tabletwo").hide();
$("tr.latent").hide();
$("tr.cust").hide();
mini.get("customerFlgo").disable();
//var urlUpd="/service/inputUpd";
var form = new mini.Form("form1");
var grid = mini.get("grid1");
grid.load();

//查询功能
$("#search").click(function(){
	grid.load({types:mini.get("types2").getText(),status:mini.get("status2").getValue(),title:mini.get("title2").getValue()});
});

//设置行样式
grid.on("drawcell", function (e) {
	if(e.field=="status"){
		if(e.value=="未处理"){
			e.cellStyle = "color:limegreen;";
		}
		if(e.value=="处理中"){
			e.cellStyle = "color:darkcyan;";
		}
		if(e.value=="已处理"){
			e.cellStyle = "color:orange;";
		}
		if(e.value=="已作废"){
			e.cellStyle = "color:red;";
		}
	}
});

//查询
function onKeyEnter(){
	grid.load({types:mini.get("types2").getText(),status:mini.get("status2").getValue(),title:mini.get("title2").getValue()});
}
//增加记录
function btnAdd(){
	if ($.trim(mini.get("types").getValue()) == 1){
		if (($.trim(mini.get("customs_id1").getValue()) == "" && $.trim(mini.get("contact1").getValue()) == "") ||
				$.trim(mini.get("title1").getValue()) == "" ||
				$.trim(mini.get("content1").getValue()) == ""
				){
			parent.$.dooDialog.alert("输入不正确，请重新输入！");
			return;
		}

		if ($.trim(mini.get("customs_id1").getValue()) == $.trim(mini.get("customs_id1").getText())){
			parent.$.dooDialog.alert("顾客投诉人不能直接输入，请重新选择！");
			return;
		}

		$.post('/service/inputSaveOne',$("#form1").serializeArray(),function(data){
			if(data.code=='OK'){
				grid.load({types:mini.get("types2").getText(),status:mini.get("status2").getValue(),title:mini.get("title2").getValue()});
				parent.$.dooDialog.alert('客服输入信息保存成功！');
			}else{
				parent.$.dooDialog.alert('客服输入信息保存失败！');
				return false;
			}
		},'json');
	}else{
		if ($.trim(mini.get("customerFlg").getValue()) == 1){
			if ($.trim(mini.get("customs_id2").getValue()) == ""){
				parent.$.dooDialog.alert("顾客咨询人尚未，请重新选择！");
				return;
			}

			if ($.trim(mini.get("content2").getValue()) == ""){
				parent.$.dooDialog.alert("咨询内容不能为空，请输入！");
				return;
			}
			
			if ($.trim(mini.get("customs_id2").getValue()) == $.trim(mini.get("customs_id2").getText())){
				parent.$.dooDialog.alert("顾客投诉人不能直接输入，请重新选择！");
				return;
			}

			$.post('/service/inputSaveOne',{types:2,customs_id1:mini.get("customs_id2").getValue(),content1:mini.get("content2").getValue()},function(data){
				if(data.code=='OK'){
					grid.load({types:mini.get("types2").getText(),status:mini.get("status2").getValue(),title:mini.get("title2").getValue()});
					parent.$.dooDialog.alert('客服输入信息保存成功！');
				}else{
					parent.$.dooDialog.alert('客服输入信息保存失败！');
					return false;
				}
			},'json');
		}else{
			if ($.trim(mini.get("customerFlgo").getValue()) == 1){
				if ($.trim(mini.get("mobile").getValue()) == "" &&
					$.trim(mini.get("tel").getValue()) == "" &&
					$.trim(mini.get("email").getValue()) == "" &&
					$.trim(mini.get("qq").getValue()) == ""
					){
					parent.$.dooDialog.alert("联系方式至少输入一项，请输入！");
					return;
				}

				if ($.trim(mini.get("content2").getValue()) == ""){
					parent.$.dooDialog.alert("咨询内容不能为空，请输入！");
					return;
				}
				var contactStr = "";
				if ($.trim(mini.get("mobile").getValue()) != ""){
					contactStr = contactStr + "手机(" + $.trim(mini.get("mobile").getValue()) + ") ";
				}
				if ($.trim(mini.get("tel").getValue()) != ""){
					contactStr = contactStr + "座机(" + $.trim(mini.get("tel").getValue()) + ") ";
				}
				if ($.trim(mini.get("email").getValue()) != ""){
					contactStr = contactStr + "邮箱(" + $.trim(mini.get("email").getValue()) + ") ";
				}
				if ($.trim(mini.get("qq").getValue()) != ""){
					contactStr = contactStr + "QQ(" + $.trim(mini.get("qq").getValue()) + ") ";
				}
				
				contactStr = 
				$.post('/service/inputSaveOne',{types:2,contact1:contactStr,content1:mini.get("content2").getValue()},function(data){
					if(data.code=='OK'){
						grid.load({types:mini.get("types2").getText(),status:mini.get("status2").getValue(),title:mini.get("title2").getValue()});
						parent.$.dooDialog.alert('客服输入信息保存成功！');
					}else{
						parent.$.dooDialog.alert('客服输入信息保存失败！');
						return false;
					}
				},'json');
			}else{
				if ($.trim(mini.get("login").getValue()) == ""){
					parent.$.dooDialog.alert("登录名不能为空，请输入！");
					return;
				}

				if ($.trim(mini.get("name").getValue()) == ""){
					parent.$.dooDialog.alert("名称不能为空，请输入！");
					return;
				}

				if ($.trim(mini.get("mobile").getValue()) == "" &&
					$.trim(mini.get("tel").getValue()) == "" &&
					$.trim(mini.get("email").getValue()) == "" &&
					$.trim(mini.get("qq").getValue()) == ""
					){
					parent.$.dooDialog.alert("联系方式至少输入一项，请输入！");
					return;
				}

				if ($.trim(mini.get("content2").getValue()) == ""){
					parent.$.dooDialog.alert("咨询内容不能为空，请输入！");
					return;
				}

				$.post('/service/inputSaveTwo',$("#form1").serializeArray(),function(data){
					if(data.code=='OK'){
						grid.load({types:mini.get("types2").getText(),status:mini.get("status2").getValue(),title:mini.get("title2").getValue()});
						parent.$.dooDialog.alert('客服输入信息保存成功！');
					}else if(data.code=='MG'){
						parent.$.dooDialog.alert(data.msg);
					}else{
						parent.$.dooDialog.alert('客服输入信息保存失败！');
						return false;
					}
				},'json');
			}
		}
	}
}

// 咨询投诉区分
mini.get("types").on("valuechanged",function(e){
	if(e.value==1){
		$("#tableone").show();
		$("#tabletwo").hide();
	}else{
		$("#tabletwo").show();
		$("#tableone").hide();
	}
});

//客户类型
mini.get("customerFlgo").on("valuechanged",function(e){
	if(e.value==1){
		$("tr.cust").hide();
	}else{
		$("tr.cust").show();
	}
});

// 咨询类型区分
mini.get("customerFlg").on("valuechanged",function(e){
	if(e.value==1){
		mini.get("customerFlgo").disable();
		mini.get("customerFlgo").setText("");
		mini.get("customs_id2").enable();
		$("tr.latent").hide();
	}else{
		mini.get("customerFlgo").enable();
		mini.get("customerFlgo").setValue(1);
		mini.get("customs_id2").disable();
		$("tr.latent").show();
	}
	$("tr.cust").hide();
	mini.get("customs_id2").setValue(0);
	mini.get("customs_id2").setText("");
});
</script>
